package Week6.J0521;

import java.util.Arrays;
import java.util.Scanner;

public class 活动安排_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] schedule = new int[n][2];
        for (int i = 0; i < schedule.length; i++) {
            schedule[i][0] = scanner.nextInt();
            schedule[i][1] = scanner.nextInt();

        }

        Arrays.sort(schedule, (a, b) -> {
            return a[0] <= b[0] ? -1 : 1;
        });

        int ret = 0, r = schedule[0][1];
        for (int i = 1; i < n; i++) {
            if (schedule[i][0] < r) { // 重叠了，选有段最小作为r
                r = Math.min(r, schedule[i][1]);
            } else { // 没重叠
                ret++;
                r = schedule[i][1];
            }
        }

        System.out.println(ret + 1); // 最后一个没有累加到
    }
}
